import http from '../http/index.js'

// 获取某人的某个仓库数据
export const getOne = (name,repo,id) => {
	return http.request({
		url : 'v3/projects/'+ id,
		method : 'GET',
		data : {private_token : uni.getStorageSync('private_token')}
	})
}

// star 一个仓库
export const putStar = (name,repo) => {
	return http.request({
		url : 'v5/user/starred/'+name+'/'+repo,
		method : 'PUT',
		data : {access_token : uni.getStorageSync('access_token')}
	})
}

// 取消 star 一个仓库
export const deleteStar = (name,repo) => {
	return http.request({
		url : 'v5/user/starred/'+name+'/'+repo,
		method : 'DELETE',
		data : {access_token : uni.getStorageSync('access_token')}
	})
}

// watch 一个仓库
export const putWatch = (name,repo) => {
	return http.request({
		url : 'v5/user/subscriptions/'+name+'/'+repo,
		method : 'PUT',
		data : {access_token : uni.getStorageSync('access_token'),watch_type : "watching"}
	})
}

// 取消 watch 一个仓库
export const deleteWatch = (name,repo) => {
	return http.request({
		url : 'v5/user/subscriptions/'+name+'/'+repo,
		method : 'DELETE',
		data : {access_token : uni.getStorageSync('access_token')}
	})
}

// fork 一个仓库
export const forkOne = (name,repo) => {
	return http.request({
		url : 'v5/repos/'+name+'/'+repo + '/forks',
		method : 'POST',
		data : {access_token : uni.getStorageSync('access_token')}
	})
}

// watch 了 某个仓库的所有人
export const getWatchers = (name,repo,page) => {
	if(!page) page = 1
	return http.request({
		url : 'v5/repos/'+name+'/'+repo + '/subscribers' ,
		method : 'GET',
		data : {access_token : uni.getStorageSync('access_token'),page:page}
	})
}

// star 了 某个仓库的所有人
export const getStargazers = (name,repo,page) => {
	if(!page) page = 1
	return http.request({
		url : 'v5/repos/'+name+'/'+repo + '/stargazers' ,
		method : 'GET',
		data : {access_token : uni.getStorageSync('access_token'),page:page}
	})
}

// fork 了 某个仓库的所有仓库
export const getForks = (name,repo,page) => {
	if(!page) page = 1
	return http.request({
		url : 'v5/repos/'+name+'/'+repo + '/forks' ,
		method : 'GET',
		data : {access_token : uni.getStorageSync('access_token'),page:page}
	})
}

// 获取一个licence 
export const getLicense = (name) => {
	if(!name) return ''
	return http.request({
		url : "v5/licenses/" + name,
		data :{access_token : uni.getStorageSync('access_token')},
		method : "GET"
	})
}

// 获取readme
export const getReadme = (name,repo,ref) => {
	return http.request({
		url : "v5/repos/" + name + "/" + repo + "/readme",
		method : "GET",
		data : {access_token : uni.getStorageSync('access_token') , owner:name,repo : repo}
	})
}

// markdown 渲染 
export const renderMarkdown = (text) => {
	return http.request({
		url :"v5/markdown",
		method : "POST",
		data :{access_token : uni.getStorageSync('access_token') , text : text}
	})
}
